package com.zem.imos.Controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zem.imos.Entity.*;
import com.zem.imos.Entity.Params.ParamsPatient;
import com.zem.imos.Service.AdminService;
import com.zem.imos.Service.DoctorService;
import com.zem.imos.Service.DrugsService;
import com.zem.imos.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class DoctorController {
    @Autowired
    private AdminService adminService;
    @Autowired
    private DrugsService drugsService;
    @Autowired
    private UserService userService;
    @Autowired
    private DoctorService doctorService;
    /**
     * 医生开药
     * @author ZEM
     * @Time 2021/11/24
     * @Description 医生就诊时给用户开药
     * 未测试
     * @test 怎么输入
     */
    @PostMapping("/registerbydoc")
    public RespEntity registerbydoc (HttpServletRequest request,  @RequestBody List<DrugsOrder> drugslist){
        return doctorService.registerbydoc(request, drugslist);
    }
    /**
     * 获取当天挂号的患者
     * @author ZEM
     * @Time 2021/11/24
     * @Description 医生获取当天挂号的患者
     * 测试
     */
    @PostMapping("/getregister")
    public RespEntity getregister (HttpServletRequest request, Integer page, Integer limit){
        Page respage = new Page(page,limit);
        return doctorService.getregister(request, respage);
    }
    /**
     * 获取就诊信息
     * @author ZEM
     * @Time 2021/11/24
     * @Description 医生获取所有已经就诊了的患者信息，即获取该医生看诊的所有患者。
     * 未测试
     */
    @PostMapping("/getvisit")
    public RespEntity  getvisit (HttpServletRequest request, Integer page, Integer limit){
        Page respage = new Page(page,limit);
        return doctorService.getvisit(request, respage);
    }

    /**
     * 医生查找药品(通过name模糊查找)
     * @author ZEM
     * @Time 2021/11/24
     * @Description 验证token的role为医生，通过药品名模糊查询药品
     * 测试
     * @test ZSQ
     */
    @PostMapping("/selectdrugsnamebydoctor")
    public RespEntity selectdrugsnamebydoctor (HttpServletRequest request, Integer page,Integer limit,String name){
        Page respage = new Page(page,limit);
        return doctorService.selectdrugsnamebydoctor(request, respage, name);
    }

    /**
     * 医生查找用户
     * @author ZEM
     * @Time 2021/11/24
     * @Description 验证token的role为医生，获取满足条件的患者信息列表
     * 未测试
     * @tset 测试报错
     */
    @PostMapping("/getuserinfobydoctor")
    public RespEntity getuserinfobydoctor (HttpServletRequest request, Integer page, Integer limit, ParamsPatient patient){
        Page respage = new Page(page,limit);
        return doctorService.getuserinfobydoctor(request, respage,patient);
    }


    /**
     * 医生提交就诊结果
     * @author ZEM
     * @Time 2021/11/24
     * @Description  医生提交就诊结果，包括registerid 症状 和结果
     * 未测试
     * @test 怎么输入
     */
    @PostMapping("/insertvisit")
    public RespEntity insertvisit (HttpServletRequest request, Visit visit){
        return doctorService.insertvisit(request, visit);
    }


    /**
     * 获取就诊信息
     * @author ZEM
     * @Time 2021/11/24
     * @Description 医生获取所有已经就诊了的患者信息，即获取该医生看诊的所有患者。
     * 未测试
     * @tset queryWrapper.eq("doctor_id", doctor.getId()); 这一句没用，doctor.getId()精度不够了，后几位对不上
     */
    //获取该医生所有看诊过的患者的个人信息
    @PostMapping("/getisvisitinfobydoctor")
    public RespEntity getisvisitinfobydoctor (HttpServletRequest request, Integer page, Integer limit) {
        Page respage = new Page(page,limit);
        return doctorService.getisvisitinfobydoctor(request, respage);
    }

    /**
     * 获取患者给药记录
     * @author ZEM
     * @Time 2021/11/24
     * @Description 验证token的role为医生，使用registerid查询返回给药记录
     * 测试
     * @test ZSQ
     */
    @PostMapping("/getdrugsorderbydoctorisvisit")
    public RespEntity getdrugsorderbydoctorisvisit (HttpServletRequest request, Integer page, Integer limit, int registerid) {
        Page respage = new Page(page,limit);
        return doctorService.getdrugsorderbydoctorisvisit(request, respage, registerid);
    }

    /**
     * 管理员获取排班信息
     * @author ZEM
     * @Time 2021/12/02
     * @Description 管理员获取排班信息
     */
    @PostMapping("/selectschedulestatus")
    public RespEntity  selectScheduleStatus (HttpServletRequest request, Long date, Long id) {
        return doctorService.selectScheduleStatus(request,date,id);
    }





}
